<template>
  <customTree :data="treeData" @click="click" :defaultActived="defaultActived" :propPartLoad="true"/>
</template>

<script>

export default {
  desc: '品类树',
  name: 'treeCategory',
  components: {
  },
  props: {
    /**
     * @Description：默认选中节点
     * @Date 2023-10-10
     * @param [节点value值]
     */
    defaultActived: {
      type: Array,
      default: () => {
        return [0]
      }
    }
  },
  created() {
    this.load()
  },
  data() {
    return {
      treeData: []
    }
  },
  methods: {
    // 加载数据
    load() {
      this.$ajax.get('/base/matr_category/all', {}).then(response => {
        if (response.code == 0) {
          this.treeData = global.utils.convertToTree(response.data, {
            rootNode: {id: 0, parentId: 0, categoryName: '所有品类'},
            keyFieldName: 'id',
            parentFieldName: 'parentId',
            labelFieldName: 'categoryName'
          }) // {CHECK_HERE}
        } else {
          this.utilMessage.error(response.msg)
        }
      })
    },

    // 节点点击时触发
    click(nodeData) {
      this.$emit('click', nodeData)
    }
  },
  watch: {
  },
  computed: {
  }
}
</script>

<style lang="scss">
</style>
